<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <script type="text/javascript" src="./script/rem.js"></script>
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  <meta content="yes" name="apple-mobile-web-app-capable">
  <meta content="yes" name="apple-touch-fullscreen">
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
  <link rel="stylesheet" type="text/css" href="./css/style.css" />
  <script type="text/javascript" src="./script/aui-slide.js"></script>
  <script type="text/javascript" src="./script/jquery.min.js"></script>
  <script type="text/javascript" src="./script/doT.min.js"></script>
  <script type="text/javascript" src="./script/base.js"></script>
  <script type="text/javascript" src="./script/api.js"></script>
  <script type="text/javascript" src="./script/aui-tab.js" ></script>
  <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>
  <style>
    body{background:url(./image/user-bg.jpg) #fff no-repeat; background-size:100% auto; padding-top:0.78rem;}
  </style>
  <div id="list">

  </div>
  <div id="list2">


<!--     <div class="user-index-t">
      <img class="user-index-t-img" src="image/gril.png" tapmode onclick="user_data()">
      <div class="user-index-t-d">
        <span>
          赚石
          <p>200</p>
        </span>
        <span>
          匿名用户
          <img src="./image/user-index-vip-1.png" tapmode onclick="user_level()">
        </span>
        <span>
          金币
          <p>200</p>
        </span>
      </div>
      <div class="user-index-setup" tapmode onclick="user_setup()">
        <i class="fa fa-cog"></i>
      </div>
    </div>

    <div class="user-index-order">
      <div class="user-index-order-t">
        商城订单
        <span tapmode onclick="order()">全部订单<i class="fa fa-angle-right"></i></span>
      </div>
      <ul>
        <li tapmode onclick="order()">
          <img src="image/user-index-order-1.png">
          <p>待付款</p>
        </li>
        <li tapmode onclick="order()">
          <img src="image/user-index-order-2.png">
          <p>待发货</p>
        </li>
        <li tapmode onclick="order()">
          <img src="image/user-index-order-3.png">
          <p>待收货</p>
        </li>
        <li tapmode onclick="order()">
          <img src="image/user-index-order-4.png">
          <p>已收货</p>
        </li>
        <li tapmode onclick="order()">
          <img src="image/user-index-order-5.png">
          <p>换货</p>
        </li>
      </ul>
    </div>

    <ul class="user-index-nav">
     <li>
       <img src="image/user-nav-1.png">
       <p>邀请码</p>
     </li>
     <li tapmode onclick="user_invite()">
       <img src="image/user-nav-2.png">
       <p>我的邀请</p>
     </li>
     <li tapmode onclick="address()">
       <img src="image/user-nav-3.png">
       <p>收货地址</p>
     </li>
     <li>
       <img src="image/user-nav-4.png">
       <p>客服电话</p>
     </li>
     <li tapmode onclick="my_achievement()">
       <img src="image/user-nav-5.png">
       <p>我的销量</p>
     </li>
     <li tapmode onclick="user_wallet()">
       <img src="image/user-nav-6.png">
       <p>我的钱包</p>
     </li>
     <li tapmode onclick="user_level()">
       <img src="image/user-nav-7.png">
       <p>缴纳会费</p>
     </li>
     <li>
       <img src="image/user-nav-8.png">
       <p>我的收藏</p>
     </li>
   </ul>

   <div class="user-gg">
    <img src="image/index-gg.jpg">
  </div>

  <div class="user-index-question">
    <h3>常见问题</h3>
  </div>
  <dl>
    <dt>
      <img src="image/user-index-question-1.png">
      <p>产品怎么样，真实吗？</p>
    </dt>
    <dd>
      <img src="image/user-index-question-2.png">
      <p>非常好的产品，不用担心</p>
    </dd>
  </dl> -->
</div>

</div>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<!-- 个人资料模板 -->
<script type="text/template" id="template">
  <div class="user-index-t">
    <img class="user-index-t-img" src="{{=it.avatar}}" tapmode onclick="user_data()">
    <div class="user-index-t-d">      
      <span>
        <div><i class="zuanshi"></i>赚石</div>
        <p>{{=it.integral}}</p>
      </span>
      <span>
        {{=it.name}}
        {{? it.level == 1}}
        <img src="./image/user-index-vip-111.png" tapmode onclick="user_level()">
        {{?? it.level == 2}}
        <img src="./image/user-index-vip-222.png" tapmode onclick="user_level()">
        {{?? it.level == 3}}
        <img src="./image/user-index-vip-333.png" tapmode onclick="user_level()">
        {{?? it.level == 4}}
        <img src="./image/user-index-vip-444.png" tapmode onclick="user_level()">
        {{??}}
        {{?}}
      </span>
      <span>
        <div><i class="jinbi"></i>金币</div>
        <p>{{=it.gold}}</p>
      </span>
    </div>
    <div class="user-index-setup" tapmode onclick="user_setup()">
      <i class="fa fa-cog"></i>
    </div>
  </div>

  <div class="user-index-order">
    <div class="user-index-order-t">
      商城订单
      <span tapmode onclick="order()">全部订单<i class="fa fa-angle-right"></i></span>
    </div>
    <ul>
      <li tapmode onclick="order(1)">
        <img src="image/user-index-order-1.png">
        <p>待付款</p>
        {{? it.count_wzf<=99 && it.count_wzf>0}}
        <i>{{=it.count_wzf}}</i>
        {{?? it.count_wzf>99}}
        <i>99</i>
        {{?}}
      </li>
      <li tapmode onclick="order(2)">
        <img src="image/user-index-order-2.png">
        <p>待发货</p>
        {{? it.count_dfh<=99 && it.count_dfh>0}}
        <i>{{=it.count_dfh}}</i>
        {{?? it.count_dfh>99}}
        <i>99</i>
        {{?}}
      </li>
      <li tapmode onclick="order(3)">
        <img src="image/user-index-order-3.png">
        <p>待收货</p>
        {{? it.count_dsh<=99 && it.count_dsh>0}}
        <i>{{=it.count_dsh}}</i>
        {{?? it.count_dsh>99}}
        <i>99</i>
        {{?}}
      </li>
      <li tapmode onclick="order(5)">
        <img src="image/user-index-order-4.png">
        <p>已收货</p>
      </li>
      <li tapmode onclick="order(6)">
        <img src="image/user-index-order-5.png">
        <p>换货</p>
        {{? it.count_thh<=99 && it.count_thh>0}}
        <i>{{=it.count_thh}}</i>
        {{?? it.count_thh>99}}
        <i>99</i>
        {{?}}
      </li>
    </ul>
  </div>

  <ul class="user-index-nav">
    <li onclick="invite_code('{{=it.invite_code}}');">
     <img src="image/user-nav-1.png">
     <p>邀请码</p>
   </li>
   <li tapmode onclick="user_invite()">
     <img src="image/user-nav-2.png">
     <p>我的邀请</p>
   </li>
   <li tapmode onclick="up_level({{=it.count_tip_apply}});">
     <img src="image/up_level.png">
     {{? it.count_tip_apply<=99 && it.count_tip_apply>0}}
     <i>{{=it.count_tip_apply}}</i>
     {{?? it.count_tip_apply>99}}
     <i>99</i>
     {{?}}
     <p>权限</p>
   </li>
   <li onclick="sendGoods();">
     <img src="image/user-nav-9.png">
     {{? it.count_tip_lx<=99 && it.count_tip_lx>0}}
     <i>{{=it.count_tip_lx}}</i>
     {{?? it.count_tip_lx>99}}
     <i>99</i>
     {{?}}
     <p>我的零售</p>
   </li>
   <li tapmode onclick="my_achievement()">
     <img src="image/user-nav-5.png">
     <p>我的业绩</p>
   </li>
   <li tapmode onclick="user_wallet()">
     <img src="image/user-nav-6.png">
     <p>我的钱包</p>
   </li>
   <li tapmode onclick="user_level()">
     <img src="image/user-nav-7.png">
     {{? it.vip_state_alert}}
     <i></i>
     {{?}}
     <p>MVP</p>
   </li>
   <li tapmode onclick="user_collection();">
     <img src="image/user-nav-8.png">
     <p>我的收藏</p>
   </li>
 </ul>

 <div class="user-gg" onclick="handleAD();">
   <img id="advertisement" src="">
 </div>

 <div class="user-index-question">
  <h3>常见问题</h3>
</div>
</script>
<!-- 常见问题 模板 -->
<script type="text/template" id="template2">
  <div class="user-index-question">
    {{~it:value:index}}
    <dl>
      <dt>
        <img src="image/user-index-question-1.png">
        <p>{{=value.question}}</p>
      </dt>
      <dd>
        <img src="image/user-index-question-2.png">
        <p>{{=value.answer}}</p>
      </dd>
    </dl>
    {{~}}
  </div>
</script>
<script type="text/javascript">

  var vip_state;

  apiready = function(){
    adType = 0;
    reloadListener();
    pullLoading();
    pullRefresh();
    loadData();
    // advertisement();
    questions();
  }

  function loadData(){
    var token = $api.getStorage('token');
    api.ajax({
      url: webAddress + '/api/auth/info',
      method: 'get',
      data: {
        values: {
        },
      },
      headers: {
        Authorization: 'Bearer ' + token,
        Accept: 'application/json',
      },
    },function(ret, err){
      if (ret) {
        // alert( JSON.stringify( ret ) );
        // 关闭下拉刷新控件
        api.refreshHeaderLoadDone();
        if (ret.data) {
          vip_state = ret.data.vip_state
          templateFun(ret.data);

        }
      } else {
        // alert( JSON.stringify( err ) );
        // 关闭下拉刷新控件
        api.refreshHeaderLoadDone();
        if (err.body.status_code == 400) {
          api.toast({
            msg: err.body.message,
            duration: 2000,
            location: 'bottom'
          });
          return false;

        }
      }
    });
  }

  // 广告
  function advertisement(){
    var token = $api.getStorage('token');
    api.ajax({
      url: webAddress + '/api/home/advertisement',
      method: 'get',
      data: {
        values: {
          position: 3,
        },
      },
      headers: {
        Authorization: 'Bearer ' + token,
        Accept: 'application/json',
      },
    },function(ret, err){
      if (ret) {
          // alert( JSON.stringify( ret ) );
          // 广告
          if (ret.data.length) {
            adType = ret.data[0].type;
            adExt = ret.data[0].ext;
            $('#advertisement').attr("src", ret.data[0].picture);
          }
        } else {
        // alert( JSON.stringify( err ) );
        // api.toast({
        //   msg: err.body.message,
        //   duration: 2000,
        //   location: 'bottom'
        // });
        // return false;
      }
    });
  }

  // 常见问题
  function questions(more){

          // 进度提示框
          api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
          });

          if (more) {
            page += 1;
          }else{
            page = 1;
          }

          var token = $api.getStorage('token');
          api.ajax({
            url: webAddress + '/api/problem/index',
            method: 'get',
            data: {
              values: {
                page: page,
                row: row,
              },
            },
            headers: {
              Authorization: 'Bearer ' + token,
              Accept: 'application/json',
            },
          },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                // 关闭上拉加载控件
                api.hideProgress();
                // 关闭下拉刷新控件
                api.refreshHeaderLoadDone();
                if (ret.data) {
                  templateFun2(ret.data,more);
                }
              } else {
                // alert( JSON.stringify( err ) );
                // 关闭上拉加载控件
                api.hideProgress();
                // 关闭下拉刷新控件
                api.refreshHeaderLoadDone();
                api.toast({
                  msg: err.body.message,
                  duration: 2000,
                  location: 'bottom'
                });
                return false;
              }
            });
        }

    // 模板赋值函数1
    function templateFun(data){
      var template = $api.byId('template');
      var dotFn = doT.template(template.innerHTML);
      var html = dotFn(data);
      var list = $api.byId('list');
      $api.html(list, html);
      advertisement();
    }

    // 模板赋值函数2
    function templateFun2(data,more){

      var template = $api.byId('template2');
      var dotFn = doT.template(template.innerHTML);
      var html = dotFn(data);
      var list = $api.byId('list2');

      if (more) {
        if (data.length) {
          $api.append(list, html);
        }else{

         api.toast({
          msg: '没有更多了',
          duration: 2000,
          location: 'bottom'
        });
         return; 
       }
     }else{
      if (data.length) {
       $api.html(list, html);
     }
   }

 }

    // 点击广告
    function handleAD(){
      if (adType == 2) {
        api.openWin({
          name: 'goods_details',
          url: './goods_details.html',
          pageParam: {
            id: adExt
          }
        });
      }else if(adType == 4){
          // 跳转网页
          api.openWin({
            name: 'web_view',
            url: './web_view.html',
            pageParam: {
              url: adExt,
              title: '广告',
            }
          });

        }else{
        }
      }

    // 上拉加载
    function pullLoading(){
      api.addEventListener({
        name: 'scrolltobottom',
        extra: {
          threshold: 0
        }
      }, function(ret, err){
        questions(1);
      });
    }

    // 下拉刷新
    function pullRefresh(){
      api.setRefreshHeaderInfo({
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
          }, function(ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            loadData();
            // advertisement();
            questions();
          });
    }

    // 监听事件 (页面刷新)
    function reloadListener(){
      api.addEventListener({
        name: 'reload',
      }, function(ret, err){
       loadData();
     });
    }

    // 订单
    function order(type) {
      api.openWin({
        name: 'order',
        url: './order.html',
        pageParam: {
          type: type
        }
      });
    }

    // 邀请码
    function invite_code(code){
      // alert(code);
      api.openWin({
        name: 'invite_code',
        url: './invite_code.html',
        pageParam: {
          code: code
        }
      });
    }

    // 客服电话
    function call(tel){
      api.call({
        type: 'tel_prompt',
        number: tel
      });
    }

    // 发货管理
    function sendGoods(){
      api.openWin({
        name: 'order_manage',
        url: './order_manage.html',
        pageParam: {
          name: 'test'
        }
      });
    }

    // 收藏
    function user_collection(){
      api.openWin({
        name: 'user_collection',
        url: './user_collection.html',
        pageParam: {
          name: 'test'
        },
        bounces: false,
        scrollEnabled: true,
      });
    }

    // 退换货
    function replacement(){
      api.openWin({
        name: 'replacement',
        url: './replacement.html',
        pageParam: {
          name: 'test'
        }
      });
    }

    function index() {
      api.openWin({
        name: 'index',
        url: './index.html',
      });
    }
    function shop() {
      api.openWin({
        name: 'shop',
        url: './shop.html',
      });
    }
    function find_index() {
      api.openWin({
        name: 'find_index',
        url: './find_index.html',
      });
    }
    function user_level() {
      api.openWin({
        name: 'user_level',
        url: './user_level.html',
        pageParam: {
          name: vip_state
        }
      });
    }

    // 用户个人资料
    function user_data() {
      api.openWin({
        name: 'user_data',
        url: './user_data.html',
      });
    }
    
    function user_invite() {
      api.openWin({
        name: 'user_invite',
        url: './user_invite.html',
      });
    }

    // 收货地址
    function up_level(is_apply) {
      if (is_apply == 1) {
        $api.setStorage('uplevel_apply', 1);
      }
      api.openWin({
        name: 'uplevel_apply',
        url: './uplevel_apply.html',
      });
    }
    
    function user_wallet() {
      api.openWin({
        name: 'user_wallet',
        url: './user_wallet.html',
      });
    }
    function my_achievement() {
      api.openWin({
        name: 'my_achievement',
        url: './my_achievement.html',
      });
    }
    function user_setup() {
      api.openWin({
        name: 'user_setup',
        url: './user_setup.html',
      });
    }


  </script>
  </html>